<?php

namespace Mobile\Controller;

/**
 * Description 反馈控制器相关接口
 * 
 * @author songanwei
 * @date 2016-1-22
 */
class FeedController extends ParentController {

    protected function _initialize() {
        parent::_initialize();
        $this->validateUtil = new \Org\Util\Validate();
    }

    /**
     * @description  用户提交反馈
     * @modify songanwei 2016-01-22
     */
    public function add() {
        $params = I('param.');
        $validateRule = array(
            'userId' => 'notnull,notempty,id',
            'content' => 'notnull,notempty,nameLength255',
            'token' => 'notnull,notempty',
        );
        $this->ajaxValidateReturn($this->validateUtil, $params, $validateRule);

        $email = $params['email'] ? $params['email'] : '';
        $userId = $params['userId'];
        $token = $params['token'];
        $content = $params['content'];
        if (!empty($email)) {
            $this->ajaxValidateReturn($this->validateUtil, $email, 'notnull,notempty,email');
        }

        $this->checkMobileToken($userId, $token);
        //添加数据

        $userFeedModel = D('UserFeed');
        $result = $userFeedModel->addInfo($userId, $content, $email);
        if ($result == false) {
            returnJson(500, 508, 'error');
        }
        returnJson(200, 200, 'success');
    }

}
